package saucaca.fragment;

import lemon.kenhnhacvn.MainActivity;
import lemon.kenhnhacvn.R;
import saucaca.CustomView.PagerSlidingTabStrip;
import saucaca.Object.SingerObject;
import saucaca.Slidingmenu.SlidingMenu;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


public class ArtistDetailFragment extends Fragment {
	SingerObject singerObject;
	MainActivity mActivity;

	PagerSlidingTabStrip tabStrip;
	ViewPager viewPager;
	ArtistDetailAdapter adapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//		getActivity().getActionBar().hide();
		View view = inflater.inflate(R.layout.viewpager_tabstrip, container, false);
		Bundle b = getArguments();
		singerObject = (SingerObject) b.getSerializable(MainActivity.ID);

		viewPager = (ViewPager) view.findViewById(R.id.viewPager);
		tabStrip = (PagerSlidingTabStrip) view.findViewById(R.id.tabs);
		adapter = new ArtistDetailAdapter(getChildFragmentManager());
		final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
		viewPager.setPageMargin(pageMargin);
		viewPager.setAdapter(adapter);
		tabStrip.setViewPager(viewPager);
		tabStrip.setOnPageChangeListener(new OnPageChangeListener() {
			@Override
			public void onPageScrollStateChanged(int arg0) {
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
			}

			@Override
			public void onPageSelected(int position) {
				switch (position) {
				case 0:
					mActivity.getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
					break;
				default:
					mActivity.getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
					break;
				}
			}
		});
		mActivity.myActionBar.setMenu(singerObject.getTXNAME(), false, false);
		return view;
	}
	@Override
	public void onHiddenChanged(boolean hidden) {
		super.onHiddenChanged(hidden);
		mActivity.myActionBar.setMenu(singerObject.getTXNAME(), false, false);
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		if (activity instanceof MainActivity) {
			mActivity = (MainActivity) activity;
		}
	}

	public class ArtistDetailAdapter extends FragmentStatePagerAdapter {
		String tag="ArtistDetailAdapter";
		public ArtistDetailAdapter(FragmentManager fm) {
			super(fm);
		}

		String pageTitle[] = { "Thông tin", "Bài hát", "Album", "Video" };

		@Override
		public CharSequence getPageTitle(int position) {
			return pageTitle[position];
		}

		@Override
		public int getCount() {
			return pageTitle.length;
		}

		@Override
		public Fragment getItem(int i) {
			switch (i) {
			case 1:
				return new OnlineSongList("", singerObject.getSINGER_ID(), "", "", "", "", "");
			case (2):
				return new AlbumSongList(getActivity(), "", singerObject.getSINGER_ID(), "", "", "", "");
			case (3):
				return new VideoList("", singerObject.getSINGER_ID(), "", "", "", "", "");
			default:
				return new ArtistDetailContent(getActivity(), singerObject);
		}
	}
	}
}
